package org.rsbot.script.methods;

import java.awt.image.BufferedImage;
import org.rsbot.bot.Bot;
import org.rsbot.script.Random;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.internal.ScriptHandler;
import org.rsbot.util.ScreenshotUtil;

public class Environment extends MethodProvider
{
  public static final int INPUT_MOUSE = 1;
  public static final int INPUT_KEYBOARD = 2;

  public Environment(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  public void setUserInput(int paramInt)
  {
    this.methods.bot.getScriptHandler().updateInput(this.methods.bot, paramInt);
  }

  public void saveScreenshot(boolean paramBoolean)
  {
    ScreenshotUtil.saveScreenshot(this.methods.bot, paramBoolean);
  }

  public BufferedImage takeScreenshot(boolean paramBoolean)
  {
    return ScreenshotUtil.takeScreenshot(this.methods.bot, paramBoolean);
  }

  public boolean enableRandom(String paramString)
  {
    for (Random localRandom : this.methods.bot.getScriptHandler().getRandoms()) {
      if (((ScriptManifest)localRandom.getClass().getAnnotation(ScriptManifest.class)).name().toLowerCase().equals(paramString.toLowerCase())) {
        if (localRandom.isEnabled()) {
          return true;
        }
        localRandom.setEnabled(true);
        return true;
      }
    }

    return false;
  }

  public boolean disableRandom(String paramString)
  {
    for (Random localRandom : this.methods.bot.getScriptHandler().getRandoms()) {
      if (((ScriptManifest)localRandom.getClass().getAnnotation(ScriptManifest.class)).name().toLowerCase().equals(paramString.toLowerCase())) {
        if (!localRandom.isEnabled()) {
          return true;
        }
        localRandom.setEnabled(false);
        return true;
      }
    }

    return false;
  }

  public void enableRandoms()
  {
    for (Random localRandom : this.methods.bot.getScriptHandler().getRandoms())
      if (!localRandom.isEnabled())
        localRandom.setEnabled(true);
  }

  public void disbleRandoms()
  {
    for (Random localRandom : this.methods.bot.getScriptHandler().getRandoms())
      if (localRandom.isEnabled())
        localRandom.setEnabled(false);
  }
}